package com.lq.file;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * 文件读取
 * @author liuqing
 * @since 2022/2/17
 */
public class FileStreamDemo {
    public static void main(String[] args) {
        File file = new File("src/liuqing.txt");
        FileInputStream f1 = null;
            try {
                f1 = new FileInputStream(file);
                for (int i = 0; i < file.length(); i++) {
                    char ch = (char)(f1.read());     //中文无法读取
                    System.out.print(ch);
                }
            } catch (FileNotFoundException e) {
                System.out.println("文件没有找到");
            } catch (Exception e){
                System.out.println("读取异常");
            }finally {
                try {
                    f1.close(); //关闭文件
                } catch (IOException e) {
                    e.printStackTrace();
                    System.out.println("关闭文件出现异常");
                }
            }
    }

/**
 * 无法读取中文字符 使用FileWriter类 与 BufferedWriter类
 */
}
